package com.jhy.new2025.string;

/**
 * 2
 * <p>
 * abcde fg  edcba gf  fgabcde
 * <p>
 * <p>
 * 输出
 * fgabcde
 */
public class RightReverse {
    public static String rightReverse(int k, String s) {
        int end = s.length() - 1;
        int start = s.length() - k;
        char[] chars = s.toCharArray();
        test1(chars,start,end);
        test1(chars,0,start-1);
        test1(chars,0,end);
        return new String(chars);
    }
    private static void test1(char[] chars, int start, int end) {
        while (start < end) {
            char temp = chars[start];
            chars[start] = chars[end];
            chars[end] = temp;
            start++;
            end--;
        }
    }

    public static void main(String[] args) {
        String s = "abcdefg";
        String s1 = rightReverse(2,s);
        System.out.println(s1);

    }
}
